package com.twu.biblioteca;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: anubhav
 * Date: 1/3/14
 * Time: 4:48 PM
 * To change this template use File | Settings | File Templates.
 */
public class MenuGenerator {

    private PrintStream outPut;

    private Map<Integer, MenuOption> menuItems;

    public MenuGenerator(PrintStream outPut) {
        this.outPut = outPut;
        this.menuItems = new HashMap<Integer, MenuOption>();
    }

    public void addItem(MenuOption itemName) {
        menuItems.put(itemName.getKey(), itemName);
    }

    public void generateMenu() {

        System.out.println("*************** Please Select an option ************");
        MenuOption option;
        for (int i = 0; i < menuItems.size(); i++) {
            option = menuItems.get(i + 1);
            outPut.println(option.getKey() + ". " + option.getDescription());
        }

    }

    public Action getAction(int key) {
        return menuItems.get(key).getAction();
    }

    public boolean isCorrectInput(int key) {
        return menuItems.containsKey(key);

    }

}
